<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>02_计算器练习</title>
</head>
<body>
<input type="text" placeholder="请输入数字" id="t1">
<br>
<input type="text" placeholder="请输入数字" id="t2"><br>
<button onclick="clac('+')">加</button>
<button onclick="clac('-')">减</button>
<button onclick="clac('*')">乘</button>
<button onclick="clac('/')">除</button>
<p>结果是:<span></span></p>
</body>
<script>

    function clac(o){
        let n1 = document.querySelector('#t1').value;
        let n2 = document.querySelector('#t2').value;
        var span = document.querySelector("span")
        n1=parseFloat(n1);
        n2=parseFloat(n2);
        switch (o) {
            case '+':
                var n3=n1+n2;
                span.E(n3)
                break;
            case '-':
                var n3=n1-n2;
                span.append(n3)
                break;
            case '*':
                var n3=n1*n2;
                span.append(n3)
                break;
            case '/':
                var n3=n1/n2;
                span.append(n3)
                break;
        }
    }
</script>
</html>